package com.hjd.shop.serviceimpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.hjd.shop.dto.goods.AddGoodsDto;
import com.hjd.shop.dto.goods.GoodsRequestPageDto;
import com.hjd.shop.entity.Goods;
import com.hjd.shop.mapper.GoodsMapper;
import com.hjd.shop.service.IGoodsService;
import org.apache.commons.lang3.StringUtils;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 商品表 服务实现类
 * </p>
 *
 * @author 我玩亚索我会C
 * @since 2020-12-09
 */
@Service(interfaceClass = IGoodsService.class)
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements IGoodsService {

    @Override
    public void insert(AddGoodsDto dto) {
        Goods goods = new Goods();
        goods.setGoodsName(dto.getGoodsName())
                .setGoodsPrice(dto.getGoodsPrice())
                .setGoodsDesc(dto.getGoodsDesc())
                .setGoodsNumber(dto.getGoodsNumber())
                .setAddTime(new Date());
        baseMapper.insert(goods);
    }

    @Override
    public Page<Goods> queryList(GoodsRequestPageDto dto) {
        Page page = new Page(dto.getCurrPage(),dto.getPageSize());
        QueryWrapper<Goods> wrapper = new QueryWrapper<Goods>()
                .eq(false, "goods_name", dto.getGoodName())
                .eq("delete_flag", false)
                .orderBy(true, false, "goods_price");
        List<Goods> goods = baseMapper.selectList(wrapper);
        return page.setRecords(goods);
    }

}
